package annotation;

import org.junit.Test;
import ymy.Student;

import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;

/**
 * @author com.ymy.hadoop
 * @date 2018/12/15 15:21
 */
public class IntrospectorApp {

    @Test
    public void test02() throws Exception{
        Student student = new Student();
        PropertyDescriptor propertyDescriptor = new PropertyDescriptor("age",Student.class);
        Method setMethod = propertyDescriptor.getWriteMethod(); // setAge
        setMethod.invoke(student,30);
        System.out.println(student.getAge());

        Method getMethod = propertyDescriptor.getReadMethod();
        System.out.println(getMethod.invoke(student,null));
        System.out.println(propertyDescriptor.getPropertyType());
    }

    @Test
    public void test01()throws Exception{
        BeanInfo beanInfo = Introspector.getBeanInfo(Student.class,Object.class);
        PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
       for (PropertyDescriptor propertyDescriptor:propertyDescriptors){
           System.out.println(propertyDescriptor.getName());
       }
    }
}
